home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacWT 0.9 / wt Source / list.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-10  |  1.9 KB  |  111 lines  |  [TEXT/CWIE]

  1. /*
  2. **  MacWT -- a 3d game engine for the Macintosh
  3. **  © 1995, Bill Hayden and Nikol Software
  4. **  Free for non-commercial use - address questions to the e-mail address below
  5. **
  6. **  Mail:           afn28988@freenet.ufl.edu (Bill Hayden)
  7. **    MacWT FTP site: ftp.circa.ufl.edu/pub/software/ufmug/mirrors/LocalSW/Hayden/
  8. **  WWW Page:       http://grove.ufl.edu:80/~nikolsw
  9. **
  10. **    All of the above addresses are due to changes sometime in 1996, so stay tuned
  11. **
  12. **  based on wt, by Chris Laurel
  13. **
  14. **  This program is distributed in the hope that it will be useful,
  15. **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. */
  18.  
  19.  
  20. #include <stdlib.h>
  21. #include "wt.h"
  22. #include "wtmem.h"
  23. #include "list.h"
  24.  
  25.  
  26. List *new_list(void)
  27. {
  28.     List *l;
  29.  
  30.     l = (List *)wtmalloc(sizeof(List));
  31.     l->node = NULL;
  32.     l->next = NULL;
  33.  
  34.     return l;
  35. }
  36.  
  37.  
  38. void add_node(List *l, void *node)
  39. {
  40.     List *t;
  41.  
  42.     t = l->next;
  43.     l->next = new_list();
  44.     l->next->node = node;
  45.     l->next->next = t;
  46. }
  47.  
  48.  
  49. void delete_node(List *l)
  50. {
  51.     List *t;
  52.  
  53.     t = l->next->next;
  54.     if (l->next->node != NULL)
  55.         wtfree(l->next->node);
  56.     wtfree(l->next);
  57.     l->next = t;
  58. }
  59.  
  60.  
  61. /* Remove a node from a list, but don't free the memory used by the node.
  62. **   Useful for moving an element from one list to another . . .
  63. */
  64. void remove_node(List *l)
  65. {
  66.     List *t;
  67.  
  68.     t = l->next->next;
  69.     wtfree(l->next);
  70.     l->next = t;
  71. }     
  72.  
  73.  
  74. void delete_list(List *l)
  75. {
  76.     while (l->next)
  77.         delete_node(l);
  78.  
  79.     wtfree(l);
  80. }
  81.  
  82.  
  83.  
  84. List *scan_list(List *l, void *data, Scan_list_function *func)
  85. {
  86.     while (l->next != NULL)
  87.         {
  88.         if (func(l, data))
  89.             break;
  90.         else
  91.             l = l->next;
  92.         }
  93.  
  94.     if (l->next == NULL)
  95.         return NULL;
  96.     else
  97.         return l;
  98. }
  99.  
  100.  
  101.  
  102. /* Basic search function for use with scan list--find an object with
  103. **   a node pointing to the same place as data.
  104. */
  105. Boolean find_node(List *l, void *data)
  106. {
  107.     return (LIST_NODE(l, void *) == data);
  108. }
  109.  
  110.  
  111.